home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / faq / faqs / motf_faq / part2 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  31.1 KB

  1. Xref: bloom-picayune.mit.edu comp.windows.x.motif:13658 news.answers:4509
  2. Newsgroups: comp.windows.x.motif,news.answers
  3. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!news.media.mit.edu!micro-heart-of-gold.mit.edu!wupost!uunet!munnari.oz.au!manuel.anu.edu.au!csc.canberra.edu.au!news
  4. From: jan@ise.canberra.edu.au (Jan Newmarch)
  5. Subject: Motif FAQ (Part 2 of 5)
  6. Message-ID: <1992Dec10.001605.10450@csc.canberra.edu.au>
  7. Followup-To: comp.windows.x.motif
  8. Keywords: FAQ question answer
  9. Sender: news@csc.canberra.edu.au
  10. Reply-To: jan@ise.canberra.edu.au (Jan Newmarch)
  11. Organization: University of Canberra
  12. Date: Thu, 10 Dec 92 00:16:05 GMT
  13. Approved: news-answers-request@MIT.Edu
  14. Expires: +1 months
  15. Lines: 764
  16.  
  17. Archive-name: motif-faq/part2
  18. Last-modified: Thu December 12 1992
  19. Version: 2.12
  20.  
  21.  
  22.  
  23. -----------------------------------------------------------------------------
  24. Subject: 28) TOPIC: MOTIF GENERATORS
  25.  
  26. -----------------------------------------------------------------------------
  27. Subject: 29)*  What prototyping tools are there to generate Motif code?
  28. [Last modified: November 92]
  29.  
  30. Answer: [An FAQ is for "personal opinions" on these tools.  I don't think it
  31. is appropriate to give such opinions through this particular posting, so I
  32. haven't included any.]
  33.  
  34. `Prototyping tools' come in two forms: those that can be used to design the
  35. interface only (GUI builder), and those that go beyond this to give support
  36. for application code (User Interface Management Systems).  There are a number
  37. of commercial and non-commercial tools of both kinds that will support the
  38. Motif interface.  They include:
  39.  
  40. GUI builders:
  41.  
  42. Builder Xcessory
  43. X Build
  44. ExoCODE/xm
  45.  
  46.  
  47. UIMS:
  48.  
  49. WINTERP
  50. ALEX
  51. Widget Creation Library
  52. UIMX
  53. Serpent
  54. TeleUse
  55. X-Designer
  56. XFaceMaker2
  57. MOTIFATION
  58. MetaCard
  59.  
  60.  
  61. Some contact addresses are:
  62.  
  63. WINTERP: You may obtain the current source, documentation, and examples via
  64. anonymous ftp from host export.lcs.mit.edu: in directory contrib/winterp you
  65. will find the compress(1)'d tar(1) file winterp.tar.Z. If you do not have
  66. Internet access you may request the source code to be mailed to you by sending
  67. a message to winterp-source%hplnpm@hplabs.hp.com or hplabs!hplnpm!winterp-
  68. source.
  69.  
  70. Serpent: The S/W is free (anonymous ftp) from ftp.sei.cmu.edu.  For more info
  71. contact erik/robert at serpent-info@sei.cmu.edu.
  72.  
  73. TeleUse: In the U.K., send mail to xtech@unipalm.co.uk or call +44 954 211862.
  74. In the US contact Telesoft at:
  75.  
  76. TeleSoft, 5959 Cornerstone Court West, San Diego, CA 92121-9891
  77.              Phone: +1 619-457-2700
  78.                     +1 619-452-1334 Fax
  79.              Email: guisales@telesoft.com (Sales),
  80.                     guisupport@telesoft.com (Customer Support)
  81.  
  82.  
  83. Builder Xcessory from ICS.  More details are available by sending a request to
  84. info@ics.com.  Address: ICS Inc., 201 Broadway, Cambridge MA 02139, Tel. (617)
  85. 621-0060, Fax. (617) 621-9555
  86.  
  87. X-Designer: From Imperial Software Technology in the UK.  Email address is
  88. sales@ist.co.uk.  (+44) 743 587055
  89.  
  90. Recently, V.I. Corporation have become the distributor for the X-Designer
  91. product in the United States.  In addition, IST and V.I. Corporation have
  92. developed a product called DVX-Designer that merges X-Designer with their GUI
  93. product called DataViews.  Other merged products are in the works.  For more
  94. information, people can contact:
  95.  
  96.         V.I. Corporation
  97.         47 Pleasant Street
  98.         Northampton, MA  01060
  99.         Phone: (413) 586-4144
  100.         Fax: (413) 586-3805
  101.         Email: vi@vicorp.com
  102.  
  103.  
  104. ExoCODE/xm: From Expert Object Corp., 7250 Cicero Avenue, Lincolnwood, IL
  105. 60646 (708)676-5555.
  106.  
  107. X Build: From Nixdorf Computer (Waltham, MA) xbuild@nixdorf.com
  108.  
  109.  
  110. ExoCode: From EXOC (Chicago, IL)
  111.  
  112. UIMX: Visual Edge Software Limited, 3870 Cote Vertu, St Laurent, Quebec, H4R
  113. 1V4, Phone: (514) 332-6430, Fax:   (514) 332-5914, or: Visual Edge Software
  114. Ltd., 101 First Street, Suite 443, Los Altos, CA 94022, Phone: (415) 948-0753,
  115. Fax:   (415) 948-0843
  116.  
  117. The Widget Creation Library: The distribution is available in several ways.
  118. The preferred approach it for you to get the compressed tar file using
  119. anonymous ftp from:
  120.  
  121.     export.lcs.mit.edu    (18.30.0.238) /contrib/Wcl.1.06.tar.Z
  122.  
  123.  
  124. XFaceMaker2: NSL -  Non Standard Logics S.A., 57-59, rue Lhomond, 75005  Paris
  125. - France, Phone: +33 (1) 43.36.77.50, Fax:   +33 (1) 43.36.59.78 email:
  126. requests@nsl.fr or requests%nsl.fr@inria.fr for information.
  127.  
  128. Their North American office: Non Standard Logics, Inc., 4141 State Street,
  129. Suite B-11, Santa Barbara CA 93110, Tel: 805 964 9599, Fax: 805 964 4367
  130.  
  131.  
  132. MOTIFATION: AKA EDV, Universitaetsstrasse 125, 4630 Bochum, Germany, Tel: +49
  133. (0) 234 / 33397-0, Fax: +49 (0) 234 / 33397-40
  134.  
  135.  
  136. ALEX: For more information contact Michael Karliner on (+44) 81 566 2307 or
  137. E-mail to alex@s-strat.co.uk.  ALEX Technologies, Waterman's Yard, 32a The
  138. Mall, Ealing, London W5, UK.
  139.  
  140. MetaCard: MetaCard 1.0 is supported on five popular UNIX/X11 platforms: SPARC,
  141. Sun3, DECstation, HP-9000/300, and SCO ODT.  An HP-9000/700 port is underway
  142. and should be available by the end of July.  [They] plan to support IBM
  143. RS/6000, SGI Iris, and DG AViiON sometime fall '92.  For more information, or
  144. to receive a free save-disabled but licensable copy of MetaCard, email to
  145. info@metacard.com or call 303- 447-3936.  If you have anonymous FTP access to
  146. the Internet, you can download the current engines, documentation, and an
  147. unlicensed Home stack from ftp.metacard.com (128.138.213.21), directory
  148. MetaCard.  Commercial users can get MetaCard from world.std.com
  149. (192.74.137.5), directory pub/Metacard.  If you don't have an anonymous ftp
  150. access, you can also download MetaCard from The World using kermit or xmodem
  151. from the ~ftp/pub/MetaCard directory.  Sign up by calling 617-739-0202 (voice)
  152. or via modem by dialing 617-739-9753 (7 bits even parity) and logging in as
  153. new.
  154.  
  155. MetaCard 1.2 Beta 5 is now available for anonymous FTP from ftp.metacard.com
  156. (directory MetaCard/1.2B5), and ftp.uu.net (directory vendor/MetaCard/1.2B5).
  157.  
  158.  
  159. -----------------------------------------------------------------------------
  160. Subject: 30) TOPIC: TEXT WIDGET
  161.  
  162. -----------------------------------------------------------------------------
  163. Subject: 31) Why does  pressing  <return> in a text widget do nothing?  This
  164. happens using Motif 1.0 when I have a text widget inside a bulletin board (or
  165. form) inside a dialog shell. (In Motif 1.1 it is fixed for both text and list
  166. widgets.)
  167.  
  168. Answer: In single line mode, pressing the <return> key usually invokes the
  169. activate() action, and in multi-line mode, the newline() action.  However,
  170. whenever a widget is the child of a bulletin board widget which is the child
  171. of a dialog shell, the bulletin board forces all of its children to translate
  172. <return> to the bulletin board action Return() which is usually associated
  173. with the default button of the dialog.  To restore the text actions of
  174. activate() or newline(), you need to overide the Return() action of the
  175. bulletin board.
  176.  
  177.  
  178.         /* declarations */
  179.         /* for a single line widget */
  180.         char newTrans[] = "<Key>Return : activate()";
  181.         /* for a multi line widget */
  182.         char newTrans[] = "<Key>Return : newline()";
  183.         XtTranslations transTable;
  184.  
  185.         /* in executable section */
  186.  
  187.         transTable = XtParseTranslationTable(newTrans);
  188.  
  189.         /* after creating but before managing text widget */
  190.  
  191.         XtOverrideTranslations(textWidget, transTable);
  192.  
  193.  
  194. -----------------------------------------------------------------------------
  195. Subject: 32) When I add text to a scrolling text widget how can I get the new
  196. text to show?
  197.  
  198. Answer: Use the call undocumented in Motif 1.0
  199.  
  200.         void XmTextShowPosition(w, position)
  201.         Widget w;
  202.         XmTextPosition position;
  203.  
  204. where the position is the number of characters from the beginning of the
  205. buffer of the text to be displayed. If you don't know how many characters are
  206. in the buffer, use another call undocumented in Motif 1.0
  207.  
  208.         position = XmTextGetLastPosition(w)
  209.  
  210.  
  211. -----------------------------------------------------------------------------
  212. Subject: 33)* Does the text widget support 16 bit character fonts?
  213.  
  214.  
  215. [Last modified: November 92]
  216.  
  217. Answer: R5 has support for 16 bit character sets, and Motif 1.2 uses that.
  218. Neither Motif 1.0 nor 1.1 support 16 bit sets.
  219.  
  220. -----------------------------------------------------------------------------
  221. Subject: 34) How can I stop the text widget from echoing characters typed?  I
  222. need to turn off echo for password input.
  223.  
  224. Answer: Use the modifyVerifyCallback to tell when input is received. Set the
  225. `doit' field in the XmTextVerifyCallbackStruct to False to stop the echo. In
  226. Motif 1.0 this will cause a beep per character: Live with it, because at 1.1
  227. you can turn it off.  Note that password hiding is inherently insecure in X -
  228. someone may have an X grab on the keyboard and be reading all characters typed
  229. in anyway.
  230.  
  231. Another solution often proposed is to set the foreground and background
  232. colours to be the same, effectively hiding the text.  This has a major flaw:
  233. someone may select the text (triple click the mouse to get the line), and then
  234. paste the password into say an xterm with *different* foreground and
  235. background colours.  This immediately shows the password.
  236.  
  237. -----------------------------------------------------------------------------
  238. Subject: 35) How can I replace characters typed with say a `*'?  I want to
  239. replace input for password entry.
  240.  
  241. Answer: In Motif 1.1 Use the modifyVerifyCallback to tell when input is
  242. received.  Set text->ptr in the callback structure to '*'. This does not work
  243. under 1.0 because of an oversight in which changes to this are ignored.  In
  244. Motif 1.0, what you can do is set the doit flag to 'false' so the text is not
  245. displayed. Then set a static boolean to True to prevent re-entrance.  Next
  246. call XmTextReplace() to display your '*'.  then reset your re-entrance flag to
  247. False.  XmTextReplace() will call the XmNmodifyVerify callback.  To prevent
  248. getting into an infinite loop, you need the re-entrance flag.
  249.  
  250. The following program from Dan Heller illustrates this:
  251. --------------
  252. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  253.  * This program is freely distributable without licensing fees and
  254.  * is provided without guarantee or warranty expressed or implied.
  255.  * This program is -not- in the public domain.  This program appears
  256.  * in the Motif Programming Manual, O'Reilly Volume 6.
  257.  */
  258.  
  259. /* passwd.c -- prompt for a passwd.  Meaning, all input looks like
  260.  * a series of *'s.  Store the actual data typed by the user in
  261.  * an internal variable.  Don't allow paste operations.  Handle
  262.  * backspacing by deleting all text from insertion point to the
  263.  * end of text.
  264.  */
  265. #include <Xm/Text.h>
  266. #include <Xm/LabelG.h>
  267. #include <Xm/RowColumn.h>
  268. #include <ctype.h>
  269.  
  270. void check_passwd();
  271. char *passwd; /* store user-typed passwd here. */
  272.  
  273. main(argc, argv)
  274. int argc;
  275. char *argv[];
  276. {
  277.     Widget        toplevel, text_w, rowcol;
  278.     XtAppContext  app;
  279.  
  280.     toplevel = XtVaAppInitialize(&app, "Demos",
  281.         NULL, 0, &argc, argv, NULL, NULL);
  282.  
  283.     rowcol = XtVaCreateWidget("rowcol",
  284.         xmRowColumnWidgetClass, toplevel,
  285.         XmNorientation, XmHORIZONTAL,
  286.         NULL);
  287.  
  288.     XtVaCreateManagedWidget("Password:",
  289.         xmLabelGadgetClass, rowcol, NULL);
  290.     text_w = XtVaCreateManagedWidget("text_w",
  291.         xmTextWidgetClass, rowcol, NULL);
  292.  
  293.     XtAddCallback(text_w, XmNmodifyVerifyCallback, check_passwd, NULL);
  294.     XtAddCallback(text_w, XmNactivateCallback, check_passwd, NULL);
  295.  
  296.     XtManageChild(rowcol);
  297.     XtRealizeWidget(toplevel);
  298.     XtAppMainLoop(app);
  299. }
  300.  
  301. void
  302. check_passwd(text_w, unused, cbs)
  303. Widget        text_w;
  304. XtPointer     unused;
  305. XmTextVerifyCallbackStruct *cbs;
  306. {
  307.     char *new;
  308.     int len;
  309.  
  310.     if (cbs->reason == XmCR_ACTIVATE) {
  311.         printf("Password: %s\n", passwd);
  312.         return;
  313.     }
  314.  
  315.     if (cbs->text->ptr == NULL) { /* backspace */
  316.         cbs->endPos = strlen(passwd); /* delete from here to end */
  317.         passwd[cbs->startPos] = 0; /* backspace--terminate */
  318.         return;
  319.     }
  320.  
  321.     if (cbs->text->length > 1) {
  322.         cbs->doit = False; /* don't allow "paste" operations */
  323.         return; /* make the user *type* the password! */
  324.     }
  325.  
  326.     new = XtMalloc(cbs->endPos + 2); /* new char + NULL terminator */
  327.     if (passwd) {
  328.         strcpy(new, passwd);
  329.         XtFree(passwd);
  330.     } else
  331.         new[0] = NULL;
  332.     passwd = new;
  333.     strncat(passwd, cbs->text->ptr, cbs->text->length);
  334.     passwd[cbs->endPos + cbs->text->length] = 0;
  335.  
  336.     for (len = 0; len < cbs->text->length; len++)
  337.         cbs->text->ptr[len] = '*';
  338. }
  339.  
  340.  
  341. -----------------------------------------------------------------------------
  342. Subject: 36) How can I best add a large piece of text to a scrolled text
  343. widget?  In some versions of Motif 1.0 even using XmTextSetString, it insists
  344. on adding the text one line at a time, adjusting the scroll bar each time. It
  345. looks awful and is slow.
  346.  
  347. Answer: If you don't have this problem, use XmTextSetString to set all of the
  348. text in the widget.  If you do have this slowdown problem even using
  349. XmTextSetString, unmanage the widget, add the text and then manage it again.
  350. This may cause the window to blink, but you have to put up with that or switch
  351. to a different version of Motif.
  352.  
  353. -----------------------------------------------------------------------------
  354. Subject: 37) How can I highlight text in the Text widget?
  355.  
  356. Answer: From: argv@zipcode.com (Dan Heller)
  357.  
  358. If you don't need font or color changes, you can do all this using a Text
  359. widget very easily [in Motif 1.1, anyway].
  360.  
  361.         loop() {
  362.             pos = offset_of_pattern_in_text_widget(pattern, text_w);
  363.             search_len = strlen(pattern);
  364.             XmTextSetHighlight(text_w, pos, pos+search_len,
  365.                         XmHIGHLIGHT_SELECTED);
  366.         }
  367.  
  368.  
  369. There are two choices for highlighting: reverse video (HIGHLIGHT_SELECTED) and
  370. underlined (HIGHLIGHT_SECONDARY_SELECTED).  Be careful that your users won't
  371. confuse your highlights with actual selections!
  372.  
  373. -----------------------------------------------------------------------------
  374. Subject: 38)  How can I select all of the text in a widget programmatically?
  375. So that some initial text is displayed, but anything typed replaces it.
  376.  
  377. Answer: XmTextSetSelection(Text1, 0, XmTextGetLastPosition(Text1), event-
  378. >xbutton.time);
  379.  
  380. where Text1 is the widget in question (obviously) and event is some event that
  381. triggered this call.  You can use XtLastTimestampProcessed( display) instead
  382. of xbutton.time if you don't happen to have an event pointer handy.
  383.  
  384.  
  385.  
  386.  
  387. -----------------------------------------------------------------------------
  388. Subject: 39) How can I change colours of text in the Text widget?  I want some
  389. of the text in one colour, some in another.
  390.  
  391. Answer: You can't.  Text stores an ordinary string, and points where
  392. `highlights' of various types begin and end.  These highlights are all the
  393. control you have over components of the text.  See the previous question.
  394.  
  395.  
  396. -----------------------------------------------------------------------------
  397. Subject: 40) How can I change the font of text in the Text widget?  I want
  398. some of the text in one font, some in another.
  399.  
  400. Answer: You can't in Text (see the previous question).  If you wanted readonly
  401. text, you could do it by using a label instead.  Label uses XmStrings, which
  402. can contain multiple character sets in the one string.
  403.  
  404. -----------------------------------------------------------------------------
  405. Subject: 41) Is there an emacs binding for the text widget?
  406.  
  407. Answer: This set is due to Kee Hinckley (nazgul@alfalfa.com):
  408.  
  409. *XmText.translations: #override\n\
  410.         Ctrl <Key>b:            backward-character()\n\
  411.         Alt <Key>b:             backward-word()\n\
  412.         Meta <Key>b:            backward-word()\n\
  413.         Shift Alt <Key>b:       backward-word(extend)\n\
  414.         Shift Meta <Key>b:      backward-word(extend)\n\
  415.         Alt <Key>[:             backward-paragraph()\n\
  416.         Meta <Key>[:            backward-paragraph()\n\
  417.         Shift Alt <Key>[:       backward-paragraph(extend)\n\
  418.         Shift Meta <Key>[:      backward-paragraph(extend)\n\
  419.         Alt <Key><:             beginning-of-file()\n\
  420.         Meta <Key><:            beginning-of-file()\n\
  421.         Ctrl <Key>a:            beginning-of-line()\n\
  422.         Shift Ctrl <Key>a:      beginning-of-line(extend)\n\
  423.         Ctrl <Key>osfInsert:    copy-clipboard()\n\
  424.         Shift <Key>osfDelete:   cut-clipboard()\n\
  425.         Shift <Key>osfInsert:   paste-clipboard()\n\
  426.         Alt <Key>>:             end-of-file()\n\
  427.         Meta <Key>>:            end-of-file()\n\
  428.         Ctrl <Key>e:            end-of-line()\n\
  429.         Shift Ctrl <Key>e:      end-of-line(extend)\n\
  430.         Ctrl <Key>f:            forward-character()\n\
  431.         Alt <Key>]:             forward-paragraph()\n\
  432.         Meta <Key>]:            forward-paragraph()\n\
  433.         Shift Alt <Key>]:       forward-paragraph(extend)\n\
  434.         Shift Meta <Key>]:      forward-paragraph(extend)\n\
  435.         Ctrl Alt <Key>f:        forward-word()\n\
  436.         Ctrl Meta <Key>f:       forward-word()\n\
  437.         Ctrl <Key>d:            kill-next-character()\n\
  438.         Alt <Key>BackSpace:     kill-previous-word()\n\
  439.         Meta <Key>BackSpace:    kill-previous-word()\n\
  440.         Ctrl <Key>w:            key-select() kill-selection()\n\
  441.         Ctrl <Key>y:            unkill()\n\
  442.         Ctrl <Key>k:            kill-to-end-of-line()\n\
  443.         Alt <Key>Delete:        kill-to-start-of-line()\n\
  444.         Meta <Key>Delete:       kill-to-start-of-line()\n\
  445.         Ctrl <Key>o:            newline-and-backup()\n\
  446.         Ctrl <Key>j:            newline-and-indent()\n\
  447.         Ctrl <Key>n:            next-line()\n\
  448.         Ctrl <Key>osfLeft:      page-left()\n\
  449.         Ctrl <Key>osfRight:     page-right()\n\
  450.         Ctrl <Key>p:            previous-line()\n\
  451.         Ctrl <Key>g:            process-cancel()\n\
  452.         Ctrl <Key>l:            redraw-display()\n\
  453.         Ctrl <Key>osfDown:      next-page()\n\
  454.         Ctrl <Key>osfUp:        previous-page()\n\
  455.         Ctrl <Key>space:        set-anchor()\n
  456.  
  457.  
  458. ! If you'd like the Delete key to work like backspace instead of deleting
  459. ! backwards, add the following definition to the lines above.
  460. !       <Key>osfDelete: delete-previous-character()\n\
  461.  
  462. ! These aren't included because they could intefere with
  463. | menu accelerators (or vice versa)
  464. !       Alt <Key>p:             backward-paragraph()\n\
  465. !       Meta <Key>p:            backward-paragraph()\n\
  466. !       Shift Alt<Key>p:        backward-paragraph(extend)\n\
  467. !       Shift Meta<Key>p:       backward-paragraph(extend)\n\
  468. !       Alt <Key>w:             copy-clipboard()\n\
  469. !       Meta <Key>w:            copy-clipboard()\n\
  470. !       Ctrl Alt <Key>w:        cut-clipboard()\n\
  471. !       Ctrl Meta <Key>w:       cut-clipboard()\n\
  472. !       Alt <Key>y:             paste-clipboard()\n\
  473. !       Meta <Key>y:            paste-clipboard()\n\
  474. !       Alt <Key>f:             forward-word()\n\
  475. !       Meta <Key>f:            forward-word()\n\
  476. !       Alt <Key>n:             forward-paragraph()\n\
  477. !       Meta <Key>n:            forward-paragraph()\n\
  478. !       Shift Alt <Key>n:       forward-paragraph(extend)\n\
  479. !       Shift Meta <Key>n:      forward-paragraph(extend)\n\
  480. !       Shift Alt <Key>f:       forward-word(extend)\n\
  481. !       Shift Meta <Key>f:      forward-word(extend)\n\
  482. !       Alt <Key>d:             kill-next-word()\n\
  483. !       Meta <Key>d:            kill-next-word()\n\
  484. !       Alt <Key>h:             select-all()\n\
  485. !       Meta <Key>h:            select-all()\n\
  486.  
  487. Similar sets of translations have been suggested by others.
  488.  
  489. -----------------------------------------------------------------------------
  490. Subject: 42) How can I use a file as the text source for a Text widget?
  491.  
  492. Answer: You can't do it directly like you can with the Athena Text widget.
  493. Instead, read the text from the file into a string (all of it!) and then use
  494. XmTextSetString.  Alternatively, read blocks of characters and add them at the
  495. end of the text using XmTextInsertString.  The following is an excerpt from
  496. Dan Heller's "file_browser.c":
  497.  
  498.     /* file_browser.c -- use a ScrolledText object to view the
  499.      * contents of arbitrary files chosen by the user from a
  500.      * FileSelectionDialog or from a single-line text widget.
  501.      */
  502.  
  503.     ...
  504.     struct stat statb;
  505.  
  506.     /* make sure the file is a regular text file and open it */
  507.     if (stat(filename, &statb) == -1 ||
  508.             (statb.st_mode & S_IFMT) != S_IFREG ||
  509.             !(fp = fopen(filename, "r"))) {
  510.         if ((statb.st_mode & S_IFMT) == S_IFREG)
  511.             perror(filename); /* send to stderr why we can't read it */
  512.         else
  513.             fprintf(stderr, "%s: not a regular file0, filename);
  514.         XtFree(filename);
  515.         return;
  516.     }
  517.  
  518.     /* put the contents of the file in the Text widget by allocating
  519.      * enough space for the entire file, reading the file into the
  520.      * allocated space, and using XmTextFieldSetString() to show the file.
  521.      */
  522.     if (!(text = XtMalloc((unsigned)(statb.st_size+1)))) {
  523.         fprintf(stderr, "Can't alloc enough space for %s", filename);
  524.         XtFree(filename);
  525.         fclose(fp);
  526.         return;
  527.     }
  528.  
  529.     if (!fread(text, sizeof(char), statb.st_size+1, fp))
  530.         fprintf(stderr, "Warning: may not have read entire file!0);
  531.  
  532.     text[statb.st_size] = 0; /* be sure to NULL-terminate */
  533.  
  534.     /* insert file contents in Text widget */
  535.     XmTextSetString(text_w, text);
  536.  
  537.  
  538.  
  539.  
  540. -----------------------------------------------------------------------------
  541. Subject: 43) How can put Text in overstrike mode instead of insert?
  542.  
  543. Answer: There is no direct way. This was posted by Edmond Pitt
  544. (ejp@bohra.cpg.oz) The correct answer to the question is to put the following
  545. in a modifyVerify callback, where 'mvcb' is the XmTextVerifyCallbackStruct,
  546. and 'overstriking' is defined by you:
  547.  
  548.     if (overstriking && mvcb->text->length == 1)
  549.     {
  550.         _XmTextDisableRedisplay(w,FALSE);
  551.         XtCallActionProc(w,"delete-next-character",mvcb->event,0);
  552.         _XmTextEnableRedisplay(w);
  553.     }
  554.  
  555. _XmText{Dis,En}ableRedisplay() are XmText{Dis,En}ableRedisplay() in 1.0, but
  556. X11R3 has no XtCallActionProc() anyway. For this environment you need my 1.0.3
  557. Text widget patches posted last year & available on request.
  558.  
  559.  
  560. -----------------------------------------------------------------------------
  561. Subject: 44) How can I make the Delete key do a backspace?
  562.  
  563. Answer: Put this in your .Xdefaults
  564.  
  565.     *XmText.translations: #override <Key>osfDelete: delete-previous-character()
  566.  
  567.  
  568. -----------------------------------------------------------------------------
  569. Subject: 45) TOPIC: LIST WIDGET
  570.  
  571. -----------------------------------------------------------------------------
  572. Subject: 46) How do I best put a new set of items into a list?
  573.  
  574. Answer: Set the new list count and list by XtSetArgs and install them by
  575. XtSetValues.
  576.  
  577.     XmString list[SIZE];
  578.     int list_size;
  579.  
  580.     XtSetArg (args[n], XmNitemCount, list_size); n++;
  581.     XtSetArg (args[n], XmNitems, list); n++;
  582.     XtSetValues (w, args, n);
  583.  
  584. Each time the list is reset by this the old contents are freed by the widget
  585. and the new supplied list is copied.  Do *not* free the old list of items
  586. yourself as this would result in the space being freed twice.  It is not
  587. necessary to remove the items one at a time, nor to "zero" out the list first.
  588.  
  589. -----------------------------------------------------------------------------
  590. Subject: 47)  Can I have strings with different fonts in a list?
  591.  
  592. Answer: Yes. The strings are XmStrings. Each one can be created using a
  593. different character set using a different font.
  594.  
  595.  
  596. -----------------------------------------------------------------------------
  597. Subject: 48) Can I get a bitmap to show in a list item like I can in a Label?
  598. I want to place a bitmap along with some normal text in my list items.
  599.  
  600. Answer: No. The list contains XmStrings, and these only allow text in various
  601. character sets. The workaround is to define your font containing the icons you
  602. want. Then you can create a fontlist containing your icon font and the font
  603. you want the text in, and then make your items multi-segment XmStrings where
  604. the first segment contains the code of the icon you want with a charset that
  605. matches the icon font in your fontlist and the second segment with a charset
  606. matching the text font.
  607.  
  608.  
  609. -----------------------------------------------------------------------------
  610. Subject: 49) Can I have items with different colours in a list?
  611.  
  612. Answer: No.  The list contains XmStrings, and these only allow text in various
  613. character sets. Since the items are XmStrings, you can already change the font
  614. of an item by replacing it with an item with the same text and a different
  615. charset tag.  Adding support for color would require modification of the
  616. internal data structure in XmList as well as modification to the drawing
  617. routines.  A possible workaround is to use a rowcolumn of buttons which can be
  618. individually set.  However, you would have to do all list functionality
  619. yourself.
  620.  
  621.  
  622. -----------------------------------------------------------------------------
  623. Subject: 50) Can I grey out an item in a list?  I want to make insensitive
  624. items in a list so that they cannot be selected.
  625.  
  626. Answer:
  627.  
  628. From W. Scott Meeks of OSF:
  629.  
  630. Unfortunately, you can't do it directly since the list items aren't individual
  631. widgets.  We've had other requests for this technology, but it didn't make the
  632. cut for 1.2; it should be in some future release.
  633.  
  634. However, you can probably fake it in your application with some difficulty.
  635. First, a list item is an XmString, so you can specify a different charset for
  636. the item than for other items in the list and then specify a font in the
  637. list's fontlist that matches the charset and gives you the visual you want.
  638. The next problem is making the item unselectable.  One idea would be to have
  639. the application keep track of the insensitive items and the items currently
  640. selected.  Then you would set up a selection callback that when called would
  641. check the item selected against the list of insensitive items and if the
  642. selected item matched would deselect that item and reselect the previously
  643. selected items.  Otherwise it would just update the application's list of
  644. selected items.  The major drawback with this approach is that you'll get
  645. flashing whenever the list selects an item and your application immediately
  646. de-selects.  Unfortunately I can't think of a way around this without mucking
  647. with the list internals.
  648.  
  649. Another alternative suggested is to use instead a column of say read only text
  650. widgets which you can make insensitive.
  651.  
  652. -----------------------------------------------------------------------------
  653. Subject: 51)  Can I have multi-line items in a list?
  654. [Last modified: August 92]
  655.  
  656. Answer: Motif 1.0 and 1.1 both have problems with multi-line items in a list.
  657. They should work okay in Motif 1.2.
  658.  
  659. -----------------------------------------------------------------------------
  660. Subject: 52)+How can I tell the position of selected items in a list?
  661.  
  662. [Last modified: Oct 92]
  663.  
  664. Answer: From  W. Scott Meeks:
  665.  
  666. 1) All XmList selection callbacks get an XmListCallbackStruct which includes
  667. the item selected and its position.  In addition, the multiple and extended
  668. selection callbacks also get a list of the selected items.  This approach
  669. requires that your application saves this information if you need it outside
  670. of the immediate callback.
  671.  
  672. 2) At any time you can XtGetValues the XmNselectedItems and
  673. XmNselectedItemCount resources.  The problem with this approach is that
  674. identical items may or may not show up in multiple times in this list and the
  675. position in the selectedItems list may not relate directly to the position in
  676. the items list.
  677.  
  678. 3) You can call XmListGetSelectedPos on the list widget.  This will return a
  679. list of the positions of all selected items.
  680.  
  681. -----------------------------------------------------------------------------
  682. Subject: 53) TOPIC: FILE SELECTION BOX WIDGET
  683.  
  684. -----------------------------------------------------------------------------
  685. Subject: 54) What is libPW.a and do I need it?  My manual says I need to link
  686. in libPW.a to use the File Selection Box.  I can't find it on my system.
  687.  
  688. Answer: The libPW.a is the Programmers Workbench library which is an ATT
  689. product not included in Berkeley based systems, hence it is not found in SunOS
  690. or Ultrix, but is found on HP-UX (a Berkeley/ATT hybrid which chose ATT in
  691. this case).  It contains the regex(3) routines (regcmp, regex).  Some systems
  692. which don't have these in the libc.a need to link with -lPW.  Some systems
  693. which have the regex(3) routines in there also have the libPW.a.  If you have
  694. regex(3) in libc, and it works, don't link with libPW.  If you don't have
  695. regex(3) in libc, and you don't have a libPW, then check some sites on the net
  696. for public domain replacements (several exist), or call your vendor.
  697.  
  698. In most versions of Motif (see the doco), you can compile FileSB.c with
  699. -DNO_REGEX if you don't have it.
  700.  
  701. -----------------------------------------------------------------------------
  702. Subject: 55) What are these compile errors: Undefined symbol _regcmp?
  703.  
  704. Answer: You need to link in the libPW library - see previous question.
  705.  
  706.  
  707. -----------------------------------------------------------------------------
  708. Subject: 56) What's wrong with the Motif 1.0 File Selection Box?  I can't set
  709. the directory, change the directory or get the file mask to work.
  710.  
  711. Answer: The 1.0 File Selection Box is broken, and these don't work.  They
  712. weren't fixed until Motif 1.04.  Use these later versions of 1.0 or switch to
  713. Motif 1.1 where it changed a lot.
  714.  
  715. Joe Hildebrand has a work-around for some of this: Before popping up an
  716. XmFileSelectionDialog, change to the directory you want.  When a file is
  717. selected, check if it is a directory, so that we can change to it.  i.e.
  718.  
  719. static void show_file_box_CB(w, client_data, call_data)
  720.    Widget               w;
  721.    Widget               client_data;
  722.    XmAnyCallbackStruct  *call_data;
  723. {
  724.    chdir("/users/hildjj/files");
  725.    XtManageChild(client_data);
  726. }
  727.  
  728. static void val_save(w, client_data, call_data)
  729.    Widget       w;
  730.    Widget       client_data;
  731.    XmSelectionBoxCallbackStruct *call_data;
  732. {
  733.    struct stat buf;  /* struct stat is defined in stat.h */
  734.    char *filename;
  735.  
  736.    /* get the file name from the FileSelectionBox */
  737.    filename = SmX(call_data->value);
  738.  
  739.    /* get the status of the file named filename, and put it into buf */
  740.    if (!stat(filename, &buf))
  741.    {
  742.       /* if it's a directory */
  743.       /* if it's a directory */
  744.       if(S_ISDIR(buf.st_mode))
  745.       {
  746.          /* change to that directory, and update the FileSelectionBox */
  747.         chdir(filename);
  748.         XmFileSelectionDoSearch(w, NULL);
  749.       }
  750.       else
  751.          /* if it's a regular file */
  752.          if(S_ISREG(buf.st_mode))
  753.             /* ask if it should be overwritten */
  754.             XtManageChild(valbox);
  755.          else
  756.             /* it's another kind of file.  What type, i can't think of,
  757.                but it might happen */
  758.             pop_up_error_box(client_data, "Error saving file");
  759.    }
  760.    else  /* we couldn't get the file status */
  761.    {
  762.       /* if it's because the file doesn't exist, we're golden */
  763.       if (errno == ENOENT)
  764.          save_file();
  765.       else   /* there is some other problem getting the status.
  766.                 e.g. bad path */
  767.          pop_up_error_box(client_data, "Error saving file");
  768.    }
  769. }
  770.  
  771. this still doesn't implement the file masking stuff.
  772.  
  773.  
  774. -----------------------------------------------------------------------------
  775. END OF PART TWO
  776. --
  777. +----------------------+---+
  778.   Jan Newmarch, Information Science and Engineering,
  779.   University of Canberra, PO Box 1, Belconnen, Act 2616
  780.   Australia. Tel: (Aust) 6-2012422. Fax: (Aust) 6-2015041
  781.